package predict.app.my_second;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    String num = null;
    String board = "sendInfo";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = (Button)findViewById(R.id.button);
        Button button2 = (Button)findViewById(R.id.button1);
        final EditText text  = (EditText)findViewById(R.id.editText);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num = text.getText().toString();
                if(PhoneNumberUtils.isGlobalPhoneNumber(num)) {
                    Intent bohao = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://" + num));
                    startActivity(bohao);
                } else {
                    Toast.makeText(MainActivity.this, "您输入的号码不正确，请重新输入", Toast.LENGTH_LONG).show();
                }

            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ceshi = new Intent(board);
                ceshi.putExtra("text", "12345");
                sendBroadcast(ceshi);
            }
        });
    }
}
